<?php

class {$controller_name} extends CI_Controller
{
    public $data = array();

    public function __construct()
    {
        parent::__construct();
        $this->load->model('{$controller_name}_model');
    }

    public function index()
    {
        $this->data['result'] = $this->{$controller_name}_model->listAll();
        $this->load->view('{$controller_name}/index', $this->data);
    }

    public function add()
    {
        $this->load->view('{$controller_name}/add', $this->data);
    }

    public function update()
    {
        $post_id = $this->input->post('id');

        if($post_id)
        {
            $save_data = array();
            {$data_str}

            if($this->{$controller_name}_model->save($save_data))
            {
                redirect(base_url(strtolower('{$controller_name}')));
            }

            redirect(base_url(strtolower('{$controller_name}') . '/update?id=' . $post_id ));
        }

        $id = (int) $this->input->get('id');
        $this->data['item'] = $this->{$controller_name}_model->get($id);
        $this->load->view('{$controller_name}/update', $this->data);
    }

    public function delete()
    {
        $id = (int) $this->input->get('id');
        $this->load->view('{$controller_name}/delete', $this->data);
    }
}